<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="string" uri="http://jakarta.apache.org/taglibs/string-1.1" %>
<%@ taglib uri="/WEB-INF/tlds/pagination.tld" prefix="pagination" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Bettersoft Portal</title>
    <link href="/common/css/indexStyle.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="/common/js/common.js"></script>
    <script type='text/javascript' src="/common/dwr/engine.js"></script>
    <script type='text/javascript' src="/common/dwr/util.js"></script>
    <script type='text/javascript' src='/dwr/interface/BettersoftPortalService.js'></script>

    <script type="text/javascript">
        dwr.engine.setErrorHandler(handler);

        function handler(error) {
            alert("error: " + error);
        }

        // 입력받은 ID와 password로 로그인을 한다. 로그인이 성공하면 회원정보를 가져와서 출력한다.
        function jsLogin() {
            var TheForm = document.frm;

            if(trim(TheForm.search_id.value) == "") {
                alert("<spring:message code="index.alert1" />");
                TheForm.search_id.value = "";
                TheForm.password.value = "";
                TheForm.search_id.focus();
                return false;
            } else if(trim(TheForm.password.value) == "") {
                alert("<spring:message code="index.alert2" />");
                TheForm.search_id.value = "";
                TheForm.password.value = "";
                TheForm.search_id.focus();
                return false;
            } else {
                TheForm.id.value = TheForm.search_id.value;
                dwr.engine.setAsync(false);
                BettersoftPortalService.logIn(TheForm.id.value, TheForm.password.value, function(result) {
                    if(result == "NON_EXIST") {
                        alert("<spring:message code="index.alert3" />");
                        TheForm.search_id.value = "";
                        TheForm.password.value = "";
                        TheForm.search_id.focus();
                        return false;
                    } else if(result == "FALSE") {
                        alert("<spring:message code="index.alert4" />");
                        TheForm.password.value = "";
                        TheForm.password.focus();
                        return false;
                    } else {
                        //TheForm.nextTarget.value = "memberInfo";	// page name(memberInfo.jsp)
                        TheForm.nextTarget.value = "main";	// page name(intro.jsp)
//                        TheForm.setLocale.value = "kr";
                        TheForm.action = "./login.do";
                        TheForm.submit();
                    }
                });
                dwr.engine.setAsync(true);
                //jsGetCommentList();
            }
        }

        // Locale 설정을 바꾼다.
        function jsChangeLocale(lan) {
            var TheForm = document.menuFrm;
            TheForm.nextTarget.value = "intro";
            TheForm.action = "${pageContext.request.contextPath}/changeLocale.do?language=" + lan;
            TheForm.submit();
        }


    </script>
</head>
<body>

<form name="frm" method="POST" onkeypress="if(event.keyCode == 13) {return false;}" >
    <input type="hidden" name="id" value=""/>
    <input type="hidden" id="nextTarget"    name="nextTarget"   value="">
    <div id="intro" style="height: 100%">
        <br/><br/><br/><br/><br/><br/><br/><br/><br/>
        <div id="login">
            <p align="center"><label for="search_id">아&nbsp;&nbsp;이&nbsp;&nbsp;디</label><input type="text" value="" id="search_id" name = "search_id" /></p>
            <p align="center"><label for="password">패스워드</label><input type="password" value="" id="password" name="password"/></p>
        </div>
        <div class="int_btn" align="center">
            <a href="javascript:jsLogin();" id="login_btn" class="btn btn_nr" style="color: #888888;"><b>로그인</b></a>
            &nbsp;&nbsp;
            <a href="register.do" id="register_btn" class="btn btn_nr" style="color: #888888;"><b>회원가입</b></a>
        </div>
    </div>
</form>
</body>
</html>